import csv,os,shutil,function
import mysql.connector
from datetime import datetime

def read_csv_file(file_path):
    arr=[]
    i=0
    with open(file_path, mode='r', encoding='utf-8') as csvfile:
        csv_reader = csv.reader(csvfile)
        for row in csv_reader:
            if i>0:
                dict=[]
                dict.append(row[8])                
                dict.append(row[1])
                arr.append(tuple(dict))
            i+=1
    return arr

csv_path = 'D:/Desk/repeat.csv'
repeat_datas=read_csv_file(csv_path)
# print(repeat_datas)

mydb = mysql.connector.connect(
  host="43.161.240.94",
  user="hcecpod_com",
  passwd="Xcd9sMZ9DMBBkbMf",
  database="hcecpod_com"
)

mycursor = mydb.cursor()


mycursor.execute("update data_model set repeat_temp = null")
mydb.commit()    # 数据表内容有更新，必须使用到该语句
print(mycursor.rowcount, "更新成功。")

i=0
for data in repeat_datas:
    mycursor.execute("update data_model set repeat_temp=%s where pic=%s",data)
    mydb.commit()    # 数据表内容有更新，必须使用到该语句
    print(i,'个',mycursor.rowcount, "更新成功。")
    i+=1

datas={}
mycursor.execute("select sort,style,position_big,rotate,define,repeat_temp from data_model where repeat_temp is not null and position_big is not null")
myresult = mycursor.fetchall()
for x in myresult:
    print(x)
    mycursor.execute("update data_model set sort=%s,style=%s,position_big=%s,rotate=%s,define=%s where position_big is null and repeat_temp=%s",x)
    mydb.commit()
    if mycursor.rowcount>0:
        print(mycursor.rowcount,"记录被修改")
